package com.emip.util;

import java.math.BigDecimal;
import java.text.DecimalFormat;

import java.io.StringWriter;

import org.codehaus.jackson.map.ObjectMapper;



public class Util {
	
	public static String trim(Object obj) {
		return obj != null ? obj.toString().trim() : "";
	}

	public static String Array2String(String[] array) {
		StringBuffer sb = new StringBuffer("(");
		for (int i = 0; i < array.length; i++) {
			if (i != 0) sb.append(",");
			sb.append("'" + array[i] + "'");
		}
		sb.append(")");
		return sb.toString();
	}
	
	public static String Float2String(String value) {
		BigDecimal bigValue = new BigDecimal(value);
		DecimalFormat df = new DecimalFormat("#.##");
		return df.format(bigValue);
	}
	
	public static String Object2String(Object obj) {
		StringWriter writer = new StringWriter();
        ObjectMapper mapper = new ObjectMapper();
        String json = null;
        try {
        	mapper.writeValue(writer, obj);
        	json = writer.toString();
		} catch (Exception e) {
			e.printStackTrace();
		}
        return json;
	}
}
